package hg.framework.utils;

import java.lang.reflect.Field;

/**
 * DB实体-处理工具
 * <p>与业务规则绑定</p>
 * @author  guoqifei
 * @since 2020-06-09
 */
public class HgBeanUtils {
    /**
     * 验证属性是否为空
     * <p>1、仅验证String类型</p>
     * <p>2、null -> ""</p>
     * @param t
     */
    public static void checkPropNull(Object t) {
        if (null == t) {
            return;
        }
        Field[] fields = t.getClass().getDeclaredFields();
        String itemVal = null;
        for (Field itemField : fields) {
            if (String.class != itemField.getType()) {
                continue;
            }
            try {
                itemField.setAccessible(true);
                itemVal = HgStringUtils.val(itemField.get(t));
                itemField.set(t, itemVal);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("EntityUtils.checkNull(),验证空,errMsg:" + e.getMessage());
                continue;
            }
        }
    }
}
